package utils.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.view.WindowManager;

public class ViewUtils {
    public static void gone(View v) {
        if (v != null)
            v.setVisibility(View.GONE);
    }

    public static void visible(View v) {
        if (v != null)
            v.setVisibility(View.VISIBLE);
    }

    public static void invisible(View v) {
        if (v != null)
            v.setVisibility(View.INVISIBLE);
    }

    public static View inflate(Context context, int layoutID) {
        return View.inflate(context, layoutID, null);
    }

    public static int getScreenWidth(Context context) {
        DisplayMetrics metric = new DisplayMetrics();
        WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        manager.getDefaultDisplay().getMetrics(metric);
        return metric.widthPixels;
    }

    public static int getScreenHight(Context context) {
        DisplayMetrics metric = new DisplayMetrics();
        WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        manager.getDefaultDisplay().getMetrics(metric);
        return metric.heightPixels;
    }

    public static int dip2pixel(Context context, float n) {
        int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, n, context.getResources().getDisplayMetrics());
        return value;
    }
}
